<?php
namespace Home\Controller;
use Common\Controller\UserController;
class ConsumerController extends UserController {
	public function user_address(){
        $this->states=M('Region')->where('pid=1')->select();
        $this->areas=M('Region')->where('pid=2')->select();
        $this->locals=M('Region')->where('pid=33')->select();
        $addressModel=M('address');
        $add=$addressModel->where('comuser_id='.session('id'))->select();
        $this->assign('tist',$add);
        $this->address = U('address');
        $this->region = U('region');
        $this->assign('del',U('del'));
        $this->display();
    }
    public function address(){
        if(IS_POST){
            $addressModel=D('address');
            $date['comuser_id']=session('id');
            $add1=I('post.add1');
            $add1=M('Region')->field('name')->where('id='.$add1)->find();
            $add2=I('post.add2');
            $add2=M('Region')->field('name')->where('id='.$add2)->find(); 
            $add3=I('post.add3');
            $add3=M('Region')->field('name')->where('id='.$add3)->find();
            $add4=I('post.add4');
            $date['address']=$add1['name'].$add2['name'].$add3['name'].$add4;
            $date['name']=I('post.name');
            $date['zip']=I('post.zip');
            $date['phone']=I('post.phone');
            $date['email']=I('post.email');
            $date['gerden']=I('post.gerden');
            $date['tel']=I('post.tel');
            if ($addressModel->create($date)) {
                $addressModel->add();
                 header('Location:'.U('user_address'));
            }else{
                 $this->error($addressModel->getError());
            }
        }       
    }
    public function del(){
            $id=I('get.id',0,'intval');
            if ($id>0) {
                $addressModel=M('address');
                M('address')->where('id='.$id)->delete();
                header('Location:'.U('user_address'));
            }
    }
    public function region(){
        if(IS_AJAX){
            $pid=I('post.pid',0,'intval');
            if($pid>0){
                $regionModel=M('Region');
                $data['status']='ok';
                $data['level']=I('post.level',0,'intval');
                $data['area'] = $regionModel->where('pid='.$pid)->select();
                $this->ajaxReturn($data);
            }
        }
    }
    public function user_collect(){

        $this->display();
    }
    public function user_center(){
        
        $this->display();
    }
}